var mysql = require('mysql');
var pool  = mysql.createPool({
    host:'localhost',
    user:'root',
    password:'',
    database:'craft'
});
 



let db = {
	select:function(sql){
        return new Promise(function(resolve,reject){
            pool.query(sql, function (err,data) {
                 if(err){
                 	reject(err)
                 }
                 resolve(data)
                
            })
        }) 
	},
    add:function(sql){
        return new Promise(function(resolve,reject){
            pool.query(sql, function (err) {
                 if(err){
                    reject(1)
                    return 
                 }
                 resolve(0)
                
            })
        }) 
    },
    del:function(sql){
        return new Promise(function(resolve,reject){
            pool.query(sql, function (err) {
                 if(err){
                    reject(1)
                    return 
                 }
                 resolve(0)
                
            })
        }) 
    },
    update:function(sql){
        return new Promise(function(resolve,reject){
            pool.query(sql, function (err) {
                 if(err){
                    reject(1)
                    return 
                 }
                 resolve(0)
                
            })
        }) 
    }
}

module.exports = db;